package net.googlecode.exigenlab.task3.salary;

import net.googlecode.exigenlab.task3.personal.Boss;
import net.googlecode.exigenlab.task3.personal.Employee;
import net.googlecode.exigenlab.task3.personal.Manager;
import net.googlecode.exigenlab.task3.personal.Worker;

/**
 * Class for calculating salary for workers.
 * 
 * @author Poddybniak Petr <a href="mailto:PPoddybniak@gmail.com">Poddybniak
 *         Petr</a>
 * @since 28.03.2011
 */
public class SalaryCalculator {
	private double empTax; // tax of employee
	private double mngTax;// tax of manager
	private double bossTax;// tax of boss
	private final static double workTime = 170;// monthly working time

	/**
	 * Default constructor. Set default taxes.
	 * 
	 */
	public SalaryCalculator() {
		this.setEmpTax(125);
		this.setMngTax(250);
		this.setBossTax(500);
	}

	/**
	 * Get tax of employee
	 * 
	 * @return tax of employee
	 */
	public double getEmpTax() {
		return this.empTax;
	}

	/**
	 * Set tax of employee
	 * 
	 * @param tax
	 *            tax of employee
	 */
	public void setEmpTax(double tax) {
		this.empTax = tax;
	}

	/**
	 * Get tax of manager
	 * 
	 * @return tax of manager
	 */
	public double getMngTax() {
		return this.mngTax;
	}

	/**
	 * Set tax of manager
	 * 
	 * @param tax
	 *            tax of manager
	 */
	public void setMngTax(double tax) {
		this.mngTax = tax;
	}

	/**
	 * Get tax of boss
	 * 
	 * @return tax of boss
	 */
	public double getBossTax() {
		return this.bossTax;
	}

	/**
	 * Set tax of the boss
	 * 
	 * @param tax
	 *            tax of the boss
	 */
	public void setBossTax(double tax) {
		this.bossTax = tax;
	}

	/**
	 * Calculating salary for employee
	 * 
	 * @param person
	 *            instance of <code>Employee</code> class
	 */
	public void getSalary(Employee person) {
		double salary = 0;
		if (person.isPerHour()) {
			salary = workTime * person.getRate();
		} else {
			salary = person.getRate() * person.getExperience();
		}
		if (person.isBonus()) {
			salary += person.getBonusAmount();
		}
		salary -= this.empTax;
		printSalary(person, salary);
	}

	/**
	 * Calculating salary for manager
	 * 
	 * @param person
	 *            instance of <code>Manager</code> class
	 */
	public void getSalary(Manager person) {
		double salary = 0;
		if (person.isPerHour()) {
			salary = workTime * person.getRate();
		} else {
			salary = person.getRate();
		}
		if (person.isBonus()) {
			salary += person.getBonusAmount();
		}
		salary -= this.mngTax;
		printSalary(person, salary);
	}

	/**
	 * Calculating salary for boss
	 * 
	 * @param person
	 *            instance of <code>Boss</code> class
	 */
	public void getSalary(Boss person) {
		double salary = 0;

		salary = workTime * person.getRate() - this.bossTax
				+ person.getBonusAmount();

		printSalary(person, salary);
	}

	/**
	 * Printing Info about worker and his Salary
	 * 
	 * @param person
	 *            instance of <code>Worker</code> class
	 * @param salary
	 *            the salary of worker
	 */
	private void printSalary(Worker person, double salary) {
		System.out.println(person.getPost() + ">> " + person.getName()
				+ ", age: " + person.getAge() + ", salary: $" + salary);
	}

}
